package com.gzhryc.common.logging;

import org.apache.log4j.LogManager;

import com.gzhryc.common.kafka.JFKafkaProducer;
import com.gzhryc.common.logging.impls.DefaultLogger;
import com.gzhryc.common.logging.impls.KafkaLogger;

import java.io.Serializable;

public abstract class Logger implements Serializable {

	private static final long serialVersionUID = 1L;

	public abstract boolean isDebug();

	public abstract void debug(String message, Object... strings);

	public abstract void info(String message, Object... strings);

	public abstract void error(String message, Object... strings);

	public abstract void warn(String message, Object... strings);

	public static Logger getLogger(Class<?> clazz) {
		DefaultLogger logger = null;
		try {
			Class.forName("org.apache.log4j.LogManager");
			logger = new DefaultLogger(LogManager.getLogger(clazz.getName()));
		} catch (Exception e) {
			logger = new DefaultLogger(null);
		}

		JFKafkaProducer producer = LoggerConfigHelper.self().getKafkaProducer();
		if (producer != null) {
			return new KafkaLogger(logger, clazz.getName());
		}
		return logger;
	}

}
